﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ToDoList.Logic
{
    public class WaitToDoListSource
    {
        /// <summary>
        /// 添加备注
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="listId"></param>
        /// <param name="eventId"></param>
        /// <returns></returns>
        public bool AddRemarks(int listId, int eventId, string newRemaks)
        {
            var ListId = TestData.DetailedLists.SingleOrDefault(list => list.ListId == listId);
            var EventId = TestData.WaitToDoLists.SingleOrDefault(items => items.EventID == eventId);
            if(ListId == null && EventId == null)
            {
                return false;
            }
            else
            {
                EventId.Remarks = newRemaks;
                return true;
            }
        }
        /// <summary>
        /// 添加过期时间
        /// </summary>
        /// <param name="listId"></param>
        /// <param name="eventId"></param>
        /// <param name="newOverdueEvent"></param>
        /// <returns></returns>
        public bool AddOverdueEvent(int listId, int eventId, string newOverdueEvent)
        {
            var ListId = TestData.DetailedLists.SingleOrDefault(list => list.ListId == listId);
            var EventId = TestData.WaitToDoLists.SingleOrDefault(items => items.EventID == eventId);
            if (ListId == null && EventId == null)
            {
                return false;
            }
            else
            {
                EventId.OverdueEvent = DateTime.Parse(newOverdueEvent);
                return true;
            }
        }
        /// <summary>
        /// 完成事项
        /// </summary>
        /// <param name="listId"></param>
        /// <param name="eventId"></param>
        /// <returns></returns>
        public bool CompletionItems(int listId, int eventId)
        {
            var ListId = TestData.DetailedLists.SingleOrDefault(list => list.ListId == listId);
            var EventId = TestData.WaitToDoLists.SingleOrDefault(items => items.EventID == eventId);
            if (ListId == null && EventId == null)
            {
                return false;
            }
            else
            {
                EventId.State = true;
                return true;
            }
        }
        /// <summary>
        /// 取消完成
        /// </summary>
        /// <param name="listId"></param>
        /// <param name="eventId"></param>
        /// <returns></returns>
        public bool Cancel(int listId, int eventId)
        {
            var ListId = TestData.DetailedLists.SingleOrDefault(list => list.ListId == listId);
            var EventId = TestData.WaitToDoLists.SingleOrDefault(items => items.EventID == eventId);
            if (ListId == null && EventId == null)
            {
                return false;
            }
            else
            {
                EventId.State = false;
                return true;
            }
        }
        /// <summary>
        /// 浏览清单下是事项
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="listId"></param>
        /// <returns></returns>
        public List<WaitToDoList> ViewItems(int userId,int listId)
        {
            var user = TestData.Users.SingleOrDefault(a => a.UserId == userId)
                .DetailedLists.SingleOrDefault(b => b.ListId == listId);
            if(user != null && user.WaitToDoLists != null)
            {
                return user.WaitToDoLists.ToList();
            }
            else
            {
                return null;
            }
            
        }
    }
}
